package com.example.mybatis.datasource;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.jdbc.DataSourceBuilder;

import javax.sql.DataSource;

public class MyDataSourceStore {

    private static final DataSource[] MASTERS = new DataSource[2];

    static {
        MASTERS[0] = (DataSourceBuilder.create()
                .driverClassName("com.mysql.cj.jdbc.Driver")
                .url("jdbc:mysql://localhost:3306/study-spring?serverTimezone=UTC")
                .username("root")
                .password("123456")
                .type(DruidDataSource.class)
                .build());
        MASTERS[1] = (DataSourceBuilder.create()
                .driverClassName("com.mysql.cj.jdbc.Driver")
                .url("jdbc:mysql://localhost:3306/study-spring2?serverTimezone=UTC")
                .username("root")
                .password("123456")
                .type(DruidDataSource.class)
                .build());
    }

    public static DataSource getFirst(){
        return MASTERS[0];
    }

    public static DataSource getSecond(){
        return MASTERS[1];
    }
}
